import {reqCategorylist1,reqCategorylist2,reqCategorylist3} from '@/api/product/Category'

const state = {
    Categorylist1:[],
    Categorylist2:[],
    Categorylist3:[],
    Category1Id:undefined,
    Category2Id:undefined,
    Category3Id:undefined
}


const mutations = {
    CATEGORY_ONE: (state,list) => {
    state.Categorylist1 = list
    
  },
  CATEGORY_TWO: (state,sss) => {
    const {list,ccc} = sss
    state.Category2Id= undefined
    state.Category3Id= undefined
    state.Categorylist2 = []
    state.Categorylist3 = []
    state.Category1Id = ccc
    state.Categorylist2 = list
  },
  CATEGORY_THREE: (state,c3) => {
    const {list,ddd} = c3
    state.Category3Id = undefined
    state.Categorylist3 = []
    state.Category2Id =ddd
    state.Categorylist3 = list
  },
  SET_CARY3ID:(state,data)=>{
    state.Category3Id = data
  }
}

const actions = {
  async changeCount({commit}){
    const result = await reqCategorylist1()
    if(result.code === 200){
        commit('CATEGORY_ONE',result.data)
    }
  },
  async changeTwo({commit},ccc){
    console.log(ccc,'111aa')
    
    const result = await reqCategorylist2(ccc)
    if(result.code === 200){
        commit('CATEGORY_TWO',{list:result.data,ccc})
    }
  },
  async changeThree({commit},ddd){
    const result = await reqCategorylist3(ddd)
    if(result.code === 200){
        commit('CATEGORY_THREE',{list:result.data,ddd})
    }
  },
  setThree({commit},id){
    commit('SET_CARY3ID',id)
  }
}



export default {
  namespaced: true,
  state,
  mutations,
  actions
}
